use crate::git::commands::RepositoryStatus;
use crate::git::commands::commit::CommitInfo;
use crossterm::event::KeyEvent;
use tokio::sync::mpsc;

// 定义系统中的所有可能事件
#[derive(Debug, Clone)]
pub enum AppEvent {
    // Git 相关事件
    GitOperationStart {
        operation: String,
    },
    GitOperationComplete {
        operation: String,
        result: GitResult,
    },
    GitOperationError {
        operation: String,
        error: String,
    },

    // UI 事件
    Render,
    Quit,
    KeyPress(KeyEvent),

    // 分支和提交相关
    BranchSelected(String),
    CommitSelected(String),

    // 对话框事件
    ShowBranchSwitchDialog {
        branch: String,
        has_changes: bool,
    },

    ShowMergeList(String),
    MergeSelected {
        branch: String,
        commit_ids: Vec<String>,
    },
    MergeCancelled,

    // Commit Diff 事件
    LoadCommitDiff(String), // commit_id
    CommitDiffLoaded(Result<String, String>), // Diff string or error message
    // 其他事件...
}

// Git操作结果
#[derive(Debug, Clone)]
pub enum GitResult {
    Branches(Vec<String>),
    Commits(Vec<CommitInfo>),
    RepoStatus(RepositoryStatus),
    CurrentBranch(String),
    MergeSuccess,
    MergeConflict { conflicts: Vec<String> },
    Success,
    // 其他结果...
}

pub type EventSender = mpsc::Sender<AppEvent>;
pub type EventReceiver = mpsc::Receiver<AppEvent>;

// 创建事件通道
pub fn create_event_channel(buffer: usize) -> (EventSender, EventReceiver) {
    mpsc::channel(buffer)
}
